/**
 * 无尽模式
 */
class EndLessRankItemUI extends eui.ItemRenderer{
    private oldData:any;
    private img_rank:eui.Image;
    private img_head:eui.Image;
    private lb_name:eui.Label;
    private lb_score:eui.Label;
    private img_mask:eui.Image;
    private lb_rank:eui.Label;
    constructor()
    {
        super();
        this.skinName = 'EndLessRankItemView';
        this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.onRemoveToStageHandler, this);   
    }

    public init()
    {
        let data = this.data;
        this.touchEnabled = false;
        if(!this.data)return;
        this.img_head.source = this.data.avatar_url;
        this.img_head.width = this.img_head.height = 80;
        this.img_head.mask = this.img_mask;
        this.lb_name.text = this.data.nick_name;
        this.lb_score.text = this.data.score;
        let rank = this.itemIndex + 1;
        this.img_rank.source = 'endless_rank_'+rank;
    }

    public dataChanged()
    {
        if(this.data == this.oldData)return;
        this.oldData = this.data;
        this.init();
    }

    protected onRemoveToStageHandler()
    {
        this.clear();
    }

    public clear()
    {
        this.data = null;
        this.oldData = null;
        this.removeEventListener(egret.Event.REMOVED_FROM_STAGE, this.onRemoveToStageHandler,this);
    }
}

window['EndLessRankItemUI'] = EndLessRankItemUI;